package org.dromara.xxmj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.dromara.xxmj.domain.CourseCategory;
import org.dromara.xxmj.mapper.CourseCategoryMapper;
import org.dromara.xxmj.service.ICourseCategoryService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 课程分类服务实现类
 *
 * @author Vincent
 */
@RequiredArgsConstructor
@Service
public class CourseCategoryServiceImpl implements ICourseCategoryService {

    private final CourseCategoryMapper baseMapper;

    /**
     * 获取所有课程分类
     *
     * @return 分类列表
     */
    @Override
    public List<CourseCategory> listAllCategories() {
        LambdaQueryWrapper<CourseCategory> wrapper = Wrappers.lambdaQuery();
        wrapper.orderByAsc(CourseCategory::getSort);
        return baseMapper.selectList(wrapper);
    }

    /**
     * 获取启用的课程分类
     *
     * @return 分类列表
     */
    @Override
    public List<CourseCategory> listEnabledCategories() {
        // 使用XML中定义的查询方式，指定字段，避免create_dept列问题
        LambdaQueryWrapper<CourseCategory> wrapper = Wrappers.lambdaQuery();
        wrapper.select(CourseCategory::getId, 
                       CourseCategory::getName, 
                       CourseCategory::getCode, 
                       CourseCategory::getSort, 
                       CourseCategory::getStatus, 
                       CourseCategory::getRemark,
                       CourseCategory::getCreateBy,
                       CourseCategory::getCreateTime,
                       CourseCategory::getUpdateBy,
                       CourseCategory::getUpdateTime);
        wrapper.eq(CourseCategory::getStatus, "0");
        wrapper.orderByAsc(CourseCategory::getSort);
        return baseMapper.selectList(wrapper);
    }

    /**
     * 根据ID获取分类
     *
     * @param id 分类ID
     * @return 分类信息
     */
    @Override
    public CourseCategory getCategoryById(Long id) {
        return baseMapper.selectById(id);
    }
} 